package huawei.js2025;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 垃圾短信识别
 */
public class Question29 {

    public static class Message{
        private int sender;
        private int receiver;

        public Message(int sender, int receiver) {
            this.sender = sender;
            this.receiver = receiver;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Message> msgs = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            Message message = new Message(sc.nextInt(), sc.nextInt());
            msgs.add(message);
        }

        int A = sc.nextInt();
        // A发送短信的接收者
        Set<Integer> AReceiver = msgs.stream().filter(m -> m.sender == A).map(m -> m.receiver).collect(Collectors.toSet());
        // A发送短信的接收者 没有发送给A的人数 L
        int L = 0;
        Map<Integer, List<Message>> senderMap = msgs.stream().collect(Collectors.groupingBy(m -> m.sender));
        for (Integer receiver : AReceiver) {
            if (!senderMap.containsKey(receiver) || senderMap.get(receiver).contains(A)) {
                L += 1;
            }
        }

        // A 发送的短信数量
        long ASendCount = msgs.stream().filter(m -> m.sender == A).count();
        long AReceiveCount = msgs.stream().filter(m -> m.receiver == A).count();
        int M = (int) (ASendCount - AReceiveCount);

        if (L > 5 || M > 10) {
            System.out.println("true " + L + " " + M);
            return;
        }

        // A 发送给X的短信数量 - A接收到X的短信数量N > 5
        Map<Integer, Long> AReceiveMap = msgs.stream().filter(m -> m.sender == A).collect(Collectors.groupingBy(m -> m.receiver, Collectors.counting()));
        for (Map.Entry<Integer, Long> entry : AReceiveMap.entrySet()) {
            Integer receive = entry.getKey();
            Long receiveCount = entry.getValue();

            long count = msgs.stream().filter(m -> m.sender == receive && m.receiver == A).count();

            int N = (int) (receiveCount - count);

            if (N > 5) {
                System.out.println("true " + L + " " + M);
                return;
            }
        }
        System.out.println("false " + L + " " + M);
    }
}
